package com.wangzifan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangzifan.mapper.StudentMapper;
import com.wangzifan.service.StudentService;
import com.wangzifan.entity.PageBean;
import com.wangzifan.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

//    @Override
//    public List<Student> queryStudent(Student student) {
//        return studentMapper.queryStudent(, student, , );
//    }

    @Override
    public void deleteStudent(List<Integer> ids) {
        studentMapper.deleteStudent(ids);
    }

    @Override
    public void addStudent(Student student) {
        studentMapper.addStudent(student);
    }

    @Override
    public Student queryStudentById(Integer id) {
        return studentMapper.queryStudentById(id);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String sno, String sname, Short gender) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);
        List<Student> students = studentMapper.queryStudent(sno, sname, gender);
        Page<Student> p = (Page<Student>) students;

        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }
}
